package com.wyd.qxglht.controller;

import java.util.List;

import javax.annotation.Resource;

import com.wyd.qxglht.dao.IUsersDao;
import com.wyd.qxglht.dao.IUsersRolesDao;
import com.wyd.qxglht.model.UsersRoles;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/usersRoles")
public class UsersRolesController {


        @Resource
        private  IUsersRolesDao usersRolesDao;

        @Resource
        private IUsersDao usersDao;



        @ApiOperation(value = "查询所有",notes = "查询所有")


        @GetMapping
        public List<UsersRoles> findAll(){

            return usersRolesDao.findAll();
        }


       

        @ApiOperation(value = "查询指定用户的所有角色",notes = "查询指定用户的所有角色")
        @ApiImplicitParam(name="userId",value ="用户编号",required=true,paramType ="path")
        @GetMapping(value = "/{userId}")
    
        public List<UsersRoles> getRoles(@PathVariable String userId){
        
          
            return usersRolesDao.getRoles(userId);
    
    
        }

             //给用户分配角色
             @ApiOperation(value = "给用户分配角色",notes = "给用户分配角色")
             @PostMapping(value="add")
      
             public UsersRoles add(@RequestBody UsersRoles u) {
                 
             
             
                 return usersRolesDao.save(u);
                 
             }


             
  @ApiOperation(value="移除用戶的角色",notes = "移除用戶的角色")
  @ApiImplicitParams({
    @ApiImplicitParam(name="userId",value ="用戶id",required=true,paramType ="path"),
    @ApiImplicitParam(name="roleId",value ="角色id",required=true,paramType ="path")
   
})
  @DeleteMapping(value = "/{userId}/{roleId}")
  public int del(@PathVariable String userId,@PathVariable String roleId){

    return usersRolesDao.delUsersRole(userId,roleId);

  }
 


}